package com.bootdo.clouddo.controller.book;


import com.bootdo.clouddo.controller.common.CommonController;
import com.bootdo.clouddo.service.book.IBookBookshelfService;
import com.bootdo.clouddo.utils.R;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/book/v1/bookshelf")
public class BookshelfController extends CommonController {

    @Autowired
    private IBookBookshelfService biz;

    @PostMapping("/star/{bookId}")
    public R star(@PathVariable Long bookId, @RequestBody Map<String, String> data){
        try{
            return R.data(biz.star(getUid(), bookId, data));
        }catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

    @GetMapping("/star/status/{bookId}")
    public R status(@PathVariable Long bookId){
        try{
            return R.data(biz.existsByUid(getUid(), bookId));
        }catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

    @GetMapping("/find")
    public R find(Integer page){
        try{
            PageHelper.startPage(page, 15);
            return R.data(biz.findByUid(getUid()));
        }catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }
}
